package d1204;


import java.util.Comparator;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

    public class Demo04 {
        //Tree set 中添加自定义对象
        public static void main(String[] args) {
            Student s1=new Student("ligui","5",56);
            Student s2=new Student("liui","6",57);
            Student s3=new Student("i","3",58);
            Student s4=new Student("idddd","4",80);
            Student s5=new Student("idddd","10",80);
            Student s6=new Student("idddd","7",80);
            // Set <Student>  studentSet=new TreeSet<>();
            TreeSet<Student> studentSet=new TreeSet<>(new Comparator<Student>() {//重写tree Set方法
                @Override
                public int compare(Student o1, Student o2) {

                    Integer io1=Integer.valueOf(o1.getId());
                    Integer io2=Integer.valueOf(o2.getId());
                    return Integer.compare(io1,io2);
                }
            });


            studentSet.add(s1);
            studentSet.add(s2);
            studentSet.add(s3);
            studentSet.add(s4);
            studentSet.add(s5);
            studentSet.add(s6);
            System.out.println("遍历"+studentSet);
            System.out.println(studentSet.first());//最高分
            System.out.println(studentSet.last());//最低分
            //System.out.println(studentSet,57);//小于60的
            //SortedSet<Student> stud= studentSet.subSet(new Student("aa",57),new Student("ss",80));
            //System.out.println("545!!!"+stud);//输出57 到80 之间的学生
            //stud.forEach(student -> System.out.println("forEach输出"+studentSet));
            //stream 流
        }
    }


